home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / docs / libgrx.doc < prev    next >
Text File  |  1993-12-06  |  82KB  |  1,508 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.                                         LIBGRX
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.                       A 16/256 color graphics library for DJGPP
  26.  
  27.                                     User's Manual
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.                                      Written by:
  42.                                      Csaba Biegl
  43.  
  44.  
  45.                                    August 10, 1992
  46.  
  47.  
  48.  
  49.  
  50.  
  51.             LIBGRX graphics library user's manual                                        2
  52.  
  53.  
  54.           Abstract
  55.  
  56.                   LIBGRX is a graphics library for DJGPP or Turbo C programs. (The Turbo C
  57.             version  was tested using TC++ 1.01) Currently  it supports VGA (32768, 256 or
  58.             16 colors),  EGA (16  colors), 8514/A (256  colors) and S3-based  (256 colors)
  59.             cards. Planned future improvements include support for Hercules cards as well.
  60.             It is upward compatible with the graphics library in DJGPP (the C part, no C++
  61.             classes).  It can use the same drivers as  the graphics library in DJGPP or it
  62.             can work  with a new driver format supporting programmable number of colors as
  63.             well.
  64.  
  65.  
  66.             Data types, function declarations
  67.  
  68.                   All  public data structures and  graphics primitives meant  for usage by
  69.             the  application program are declared/prototyped  in the header  files (in the
  70.             'include' sub-directory):
  71.  
  72.                   GRDRIVER.H        graphics driver format specifications
  73.                   MOUSEX.H          cursor, mouse and keyboard handling
  74.                   GRX.H             drawing-related structures and functions
  75.                   GRXFILE.H         file formats and file access routines
  76.                   GRXFONT.H         format of a font when loaded into memory
  77.  
  78.  
  79.             Setting video modes
  80.  
  81.                   Before a program  can do any  graphics drawing it  has to configure  the
  82.             display  adapter of the PC for the desired  graphics mode. It is done with the
  83.             'GrSetMode' function as follows:
  84.  
  85.                  #ifdef __cplusplus
  86.                    void  GrSetMode(int which,int width=0,int height=0,int colors=0);
  87.                  #else
  88.                    void  GrSetMode(int which,...);
  89.                  #endif
  90.  
  91.             The  'mode' parameter  can be  one  of the  following  constants, declared  in
  92.             "grx.h":
  93.  
  94.             typedef enum {
  95.                      GR_80_25_text,
  96.                      GR_default_text,
  97.                      GR_width_height_text,
  98.                      GR_biggest_text,
  99.                      GR_320_200_graphics,
  100.                      GR_default_graphics,
  101.                      GR_width_height_graphics,
  102.                      GR_biggest_noninterlaced_graphics,
  103.                      GR_biggest_graphics,
  104.                      GR_width_height_color_graphics
  105.  
  106.  
  107.  
  108.  
  109.  
  110.                  LIBGRX graphics library user's manual                                                         3
  111.  
  112.  
  113.           } GR_graphics_modes;
  114.  
  115.                   The 'GR_width_height_text' and 'GR_width_height_graphics'  modes require
  116.             the two optional size arguments, and the 'GR_width_height_color_graphics' mode
  117.             requires all  three optional arguments.  A call with  any other mode  does not
  118.             require any of the optional arguments.
  119.  
  120.             NOTE: the 'GR_width_height_color_graphics' mode  is a new mode supported  only
  121.             if:  (1)  you  have  a  new  format  graphics  driver  (see  the  accompanying
  122.             documentation in the file "DRIVERS.DOC"),  and (2) you have a  recent (version
  123.             1.06, dated after the middle  of April 1992) copy  of GO32 which knows how  to
  124.             deal with the new driver format.
  125.  
  126.             New  format graphics drivers operating  in the proper  environment (see above)
  127.             can provide a table of the supported text and graphics modes using:
  128.  
  129.                  void  GrGetDriverModes(GR_DRIVER_MODE_ENTRY **ttable,GR_DRIVER_MODE_ENTRY **gtable)
  130.  
  131.             The arguments  'ttable' and 'gtable'  should be addresses  of pointers  to the
  132.             'GR_DRIVER_MODE_ENTRY'  structure defined  in  the include  file "grdriver.h".
  133.             Upon  return  the  pointer  variables  will  point  to  two  arrays  of  these
  134.             structures,   one  for   the  text   modes,  the   other  for   graphics.  The
  135.             'GR_DRIVER_MODE_ENTRY' structure has the following fields:
  136.  
  137.             typedef struct {
  138.                      unsigned short  width;
  139.                      unsigned short  height;
  140.                      unsigned short  number_of_colors;
  141.                      unsigned char   BIOS_mode;
  142.                      unsigned char   special;
  143.                  } GR_DRIVER_MODE_ENTRY;
  144.  
  145.             The first four structure  members should be obvious,  but the 'special'  field
  146.             may  deserve some explanation. It is non-zero  if the driver does some special
  147.             "tricks" to put the card into the desired mode. An example might be the 43 row
  148.             EGA text mode:  for this first  the "standard" 80x25 text  mode is set  up and
  149.             then  the  character  generator is  re-loaded  with  a  smaller font.  If  the
  150.             'special' field is zero then the  driver simply invokes the INT 10  function 0
  151.             BIOS routine with the mode in the 'BIOS_mode' slot.
  152.  
  153.                   A user-defined  function can be  invoked every  time the  video mode  is
  154.             changed  (i.e. 'GrSetMode'  is  called). This  function  should not  take  any
  155.             parameters and its return value (if any) is  ignored. It can be installed (for
  156.             all subsequent 'GrSetMode' calls) with the:
  157.  
  158.             void    GrSetModeHook(void (*callback)(void));
  159.  
  160.             function. The current graphics  mode (one of the valid  'mode' argument values
  161.             for 'GrSetMode') can be obtained with the:
  162.  
  163.             int     GrCurrentMode(void);
  164.  
  165.  
  166.  
  167.  
  168.  
  169.             LIBGRX graphics library user's manual                                        4
  170.  
  171.  
  172.           function, while the  type of the installed graphics adapter  can be determined
  173.             with the
  174.  
  175.             int     GrAdapterType(void);
  176.  
  177.             function.  'GrAdapterType' returns  the  type of  the adapter  as  one of  the
  178.             following three symbolic constants (defined in "grx.h"):
  179.  
  180.             #define GR_VGA          0               /* VGA adapter */
  181.                  #define GR_EGA          1               /* EGA adapter */
  182.                  #define GR_HERC         2               /* Hercules mono adapter */
  183.                  #define GR_8514A        3               /* 8514/A or compatible */
  184.                  #define GR_S3           4               /* S3 graphics accelerator */
  185.  
  186.  
  187.  
  188.  
  189.  
  190.             LIBGRX graphics library user's manual                                        5
  191.  
  192.  
  193.           Graphics contexts
  194.  
  195.                   The library supports  a set  of drawing regions  called 'contexts'  (the
  196.             'GrContext'  structure). These  can be  in video memory  or in  system memory.
  197.             Contexts  in system  memory always  have the  same memory organization  as the
  198.             video memory. When  'GrSetMode' is called, a default context  is created which
  199.             maps to the whole  graphics screen. Contexts are described by  the 'GrContext'
  200.             data structure:
  201.  
  202.                  typedef struct _GR_context_ {
  203.                      char  far *gc_baseaddr;             /* base address of display memory */
  204.                      long  gc_frameaddr;                 /* upper left corner coordinate */
  205.                      long  gc_planeoffset;               /* offset to next color plane */
  206.                      int   gc_lineoffset;                /* offset to next scan line in bytes */
  207.                      char  gc_onscreen;                  /* is it in video memory ? */
  208.                      char  gc_memflags;                  /* memory allocation flags */
  209.                      int   gc_xmax;                      /* max X coord (width  - 1) */
  210.                      int   gc_ymax;                      /* max Y coord (height - 1) */
  211.                      int   gc_xcliplo;                   /* low X clipping limit */
  212.                      int   gc_ycliplo;                   /* low Y clipping limit */
  213.                      int   gc_xcliphi;                   /* high X clipping limit */
  214.                      int   gc_ycliphi;                   /* high Y clipping limit */
  215.                      int   gc_usrxbase;                  /* user window min X coordinate */
  216.                      int   gc_usrybase;                  /* user window min Y coordinate */
  217.                      int   gc_usrwidth;                  /* user window width */
  218.                      int   gc_usrheight;                 /* user window height */
  219.                      int   gc_xoffset;                   /* X offset from root's base */
  220.                      int   gc_yoffset;                   /* Y offset from root's base */
  221.                      struct _GR_context_ *gc_root;       /* context which owns frame buf */
  222.                  } GrContext;
  223.  
  224.                   There  is  a  subtype  of   the  'GrContext'  structure.  The  structure
  225.             'GrVidRAM' contains only the  first slots of a  context describing the  memory
  226.             layout  of a  context. This  structure is  used as a  component of  other more
  227.             complex data structures in the library.
  228.  
  229.             typedef struct {
  230.                      char  far *gc_baseaddr;             /* base address of display memory */
  231.                      long  gc_frameaddr;                 /* upper left corner coordinate */
  232.                      long  gc_planeoffset;               /* offset to next color plane */
  233.                      int   gc_lineoffset;                /* offset to next scan line in bytes */
  234.                      char  gc_onscreen;                  /* is it in video memory ? */
  235.                      char  gc_memflags;                  /* memory allocation flags */
  236.                  } GrVidRAM;
  237.  
  238.                   The  following four functions return information about the layout of and
  239.             memory  occupied by  a graphics  context of  size 'width'  by 'height'  in the
  240.             current graphics mode (as set up by 'GrSetMode'):
  241.  
  242.             int     GrLineOffset(int width);
  243.                  int     GrNumPlanes(void);
  244.  
  245.  
  246.  
  247.  
  248.  
  249.                  LIBGRX graphics library user's manual                                                         6
  250.  
  251.  
  252.           long    GrPlaneSize(int w,int h);
  253.                  long    GrContextSize(int w,int h);
  254.  
  255.             'GrLineOffset'  always returns the offset between successive pixel rows of the
  256.             context in  bytes. 'GrNumPlanes'  returns the number  of bitmap planes  in the
  257.             current graphics mode. 'GrContextSize' calculates  the total amount of  memory
  258.             needed by a context, while 'GrPlaneSize' calculates the size of  a bitplane in
  259.             the context. The function:
  260.  
  261.             GrContext *GrCreateContext(int w,int h,char far *memory,GrContext *where);
  262.  
  263.             can be used to create a new context in system memory. The NULL pointer is also
  264.             accepted  as the value of the 'memory' and 'where' arguments, in this case the
  265.             library allocates the necessary amount of memory internally.
  266.  
  267.                   It  is  a general  convention in  the  library that  functions returning
  268.             pointers to any  LIBGRX specific data structure have a  last argument (most of
  269.             the time  named 'where'  in the  prototypes)  which can  be used  to pass  the
  270.             address of the data structure  which should be filled with the result. If this
  271.             'where' pointer  has the value of  NULL, then the library  allocates space for
  272.             the data structure internally. 
  273.  
  274.             The function:
  275.  
  276.             GrContext *GrCreateSubContext(int x1,int y1,int x2,int y2,GrContext *parent,GrContext *where);
  277.  
  278.             creates a  new sub-context which  maps to a part  of an existing  context. The
  279.             coordinate  arguments  ('x1' through  'y2')  are interpreted  relative  to the
  280.             parent context's limits. Pixel addressing is zero-based even  in sub-contexts,
  281.             i.e.  the address of the top  left pixel is (0,0) even  in a sub-context which
  282.             has been mapped onto the interior of its parent context.
  283.  
  284.                   Sub-contexts  can  be  resized,  but not  their  parents  (i.e. anything
  285.             returned by  'GrCreateContext' or set up  by 'GrSetMode' cannot be  resized --
  286.             because  this  could  lead to  irrecoverable  "loss"  of  drawing memory.  The
  287.             following function can be used for this purpose:
  288.  
  289.             void    GrResizeSubContext(GrContext *context,int x1,int y1,int x2,int y2);
  290.  
  291.                   The current context  structure is  stored in  a static  location in  the
  292.             library. (For efficiency reasons -- it  is used quite frequently, and this way
  293.             no  pointer  dereferencing  is  necessary.) The  context  stores  all relevant
  294.             information  about  the  video  organization, coordinate  limits,  etc...  The
  295.             current context can be set with the:
  296.  
  297.             void    GrSetContext(GrContext *context);
  298.  
  299.             function.  This function will reset  the current context  to the full graphics
  300.             screen if it is passed the NULL  pointer as argument. The value of the current
  301.             context can be saved into a 'GrContext' structure pointed to by 'where' using:
  302.  
  303.  
  304.  
  305.  
  306.  
  307.                  LIBGRX graphics library user's manual                                                         7
  308.  
  309.  
  310.           GrContext *GrSaveContext(GrContext *where);
  311.  
  312.             (Again, if  'where' is NULL, the library allocates the space.) Contexts can be
  313.             destroyed with: 
  314.  
  315.             void    GrDestroyContext(GrContext *context);
  316.  
  317.             This function  will free the  memory occupied  by the context  only if  it was
  318.             allocated originally by the library. The next three functions set up and query
  319.             the clipping limits associated with the context:
  320.  
  321.             void    GrSetClipBox(int x1,int y1,int x2,int y2);
  322.                  void    GrGetClipBox(int *x1p,int *y1p,int *x2p,int *y2p);
  323.                  void    GrResetClipBox(void);
  324.  
  325.             'GrResetClipBox' sets the  clipping limits to the limits of context. These are
  326.             the limits set  up initially  when a  context is  created. The  limits of  the
  327.             current context can be obtained using the following functions:
  328.  
  329.             int     GrMaxX(void);
  330.                  int     GrMaxY(void);
  331.                  int     GrSizeX(void);
  332.                  int     GrSizeY(void);
  333.  
  334.             The  'Max' functions  return the  biggest valid  coordinate, while  the 'Size'
  335.             functions return  a  value  one higher.  The  limits of  the  graphics  screen
  336.             (regardless of the current context) can be obtained with: 
  337.  
  338.             int     GrScreenX(void);
  339.                  int     GrScreenY(void);
  340.  
  341.  
  342.             Color management
  343.  
  344.                   The  library supports two models for color management. In the 'indirect'
  345.             (or  color table)  mode colors can  be allocated  with the  highest resolution
  346.             supported  by the  hardware (EGA:  2 bits,  VGA: 6  bits) with respect  to the
  347.             component color  intensities. In  the 'direct' or  RGB mode color  indices map
  348.             directly into  component color  intensities with non-overlapping  bitfields of
  349.             the color index representing  the component colors. The RGB mode  is supported
  350.             in 256 color and 32768 color VGA modes only (for 32768 colors this is the only
  351.             mode because of  the limitations of the VGA hardware with HiColor DAC). In RGB
  352.             mode the color index maps to component color intensities as follows:
  353.  
  354.                 256:    rrrgggbb          (3 bits for red and green, 2 for blue)
  355.                 32768:  xrrrrrgggggbbbbb  (5 bits for each component color)
  356.  
  357.                   The RGB mode is not supported in 16 color EGA and VGA modes as there are
  358.             too few available  colors to provide adequate  coverage. The advantage  of the
  359.             RGB  mode  is  faster   color  allocation  (no  table  lookup,   DAC  register
  360.  
  361.  
  362.  
  363.  
  364.  
  365.             LIBGRX graphics library user's manual                                        8
  366.  
  367.  
  368.           programming, etc...) its disadvantage is the relatively crude approximation of
  369.             the component color intensities.
  370.  
  371.                   After  the first 'GrSetMode' call  two colors are  always defined: black
  372.             and white. The indices of these two colors are returned by the functions:
  373.  
  374.             int     GrBlack(void);
  375.                  int     GrWhite(void);
  376.  
  377.             NOTE: unlike  the original DJGPP library,  LIBGRX does not  guarantee that the
  378.             white color
  379.             has the color index value of one. (GrBlack still returns 0). 
  380.  
  381.                   The  library supports  four  write modes:  write,  XOR, logical  OR  and
  382.             logical AND. These can be selected with OR-ing the color index with one of the
  383.             following constants declared in "grx.h":
  384.  
  385.             #ifdef __TURBOC__
  386.                  # define GrXOR          0x100           /* to "XOR" any color to the screen */
  387.                  # define GrOR           0x200           /* to "OR" to the screen */
  388.                  # define GrAND          0x300           /* to "AND" to the screen */
  389.                  #endif
  390.                  #ifdef __GNUC__                         /* changed for 16 bit colors */
  391.                  # define GrXOR          0x10000         /* to "XOR" any color to the screen */
  392.                  # define GrOR           0x20000         /* to "OR" to the screen */
  393.                  # define GrAND          0x30000         /* to "AND" to the screen */
  394.                  #endif
  395.                  #define GrWRITE         0               /* write color */
  396.                  #define GrNOCOLOR       (GrXOR | 0)     /* GrNOCOLOR is used for "no" color */
  397.  
  398.             NOTE: 'GrXOR'  was declared to be  "0x100" in the original  DJGPP library, but
  399.             its value had to be changed  in LIBGRX in anticipation of the 32768  color VGA
  400.             support.
  401.  
  402.             By convention, the no-op color is  obtained by combining color index 0 (black)
  403.             with  the  XOR operation.  This no-op  color has  been  defined in  "grx.h" as
  404.             'GrNOCOLOR'.
  405.  
  406.             The number of colors in the current graphics mode is returned by the:
  407.  
  408.             int     GrNumColors(void);
  409.  
  410.             function,  while the  number of  unused, available  color  can be  obtained by
  411.             calling:
  412.  
  413.             int     GrNumFreeColors(void);
  414.  
  415.             Colors can be allocated with the:
  416.  
  417.             int     GrAllocColor(int r,int g,int b);
  418.  
  419.  
  420.  
  421.  
  422.  
  423.             LIBGRX graphics library user's manual                                        9
  424.  
  425.  
  426.           function (component intensities can range from 0 to 255), or with the:
  427.  
  428.             int     GrAllocCell(void);
  429.  
  430.             function. In the second case the  component intensities of the returned  color
  431.             can be set with:
  432.  
  433.             void    GrSetColor(int color,int r,int g,int b);
  434.  
  435.             Both  'Alloc' functions  return 'GrNOCOLOR' if  there are no  more free colors
  436.             available. Additionally  'GrAllocCell'  always returns  'GrNOCOLOR'  when  the
  437.             color system is in RGB mode, as colors returned  by 'GrAllocCell' are meant to
  438.             be changed --  what is not  supposed to be  done in RGB  mode. Also note  that
  439.             'GrAllocColor' operates  much more efficiently in RGB  mode, and that it never
  440.             returns 'GrNOCOLOR' in this case.
  441.  
  442.             Color table entries can be freed (when not in RGB mode) by calling:
  443.  
  444.             void    GrFreeColor(int color);
  445.  
  446.             The component intensities of any color can be queried using the function:
  447.  
  448.             void    GrQueryColor(int c,int *r,int *g,int *b);
  449.  
  450.                   Initially  the color system is  in color table  (indirect) mode. (Except
  451.             for  the 32768 color VGA  modes which are  always in RGB mode.)  256 color VGA
  452.             modes can be put into the RGB mode by calling:
  453.  
  454.             void    GrSetRGBcolorMode(void);
  455.  
  456.             The  color system  can  be reset  (i.e.  put back  into  color table  mode  if
  457.             possible, all colors freed except for black and white) by calling:
  458.  
  459.             void    GrResetColors(void);
  460.  
  461.             The function:
  462.  
  463.             void    GrRefreshColors(void);
  464.  
  465.             reloads the currently  allocated color  values into the  video hardware.  This
  466.             function is not needed in typical applications, unless the  display adapter is
  467.             programmed directly by the application.
  468.  
  469.             Graphics primitives
  470.  
  471.                   The  screen, the current context or the  current clip box can be cleared
  472.             (i.e.set toadesired backgroundcolor)by usingoneof thefollowingthree functions:
  473.  
  474.             void    GrClearScreen(int bg);
  475.                  void    GrClearContext(int bg);
  476.                  void    GrClearClipBox(int bg);
  477.  
  478.  
  479.  
  480.  
  481.  
  482.             LIBGRX graphics library user's manual                                       10
  483.  
  484.  
  485.           The following line drawing graphics primitives are supported by the library:
  486.  
  487.             void    GrPlot(int x,int y,int c);
  488.                  void    GrLine(int x1,int y1,int x2,int y2,int c);
  489.                  void    GrHLine(int x1,int x2,int y,int c);
  490.                  void    GrVLine(int x,int y1,int y2,int c);
  491.                  void    GrBox(int x1,int y1,int x2,int y2,int c);
  492.                  void    GrCircle(int xc,int yc,int r,int c);
  493.                  void    GrEllipse(int xc,int yc,int xa,int ya,int c);
  494.                  void    GrCircleArc(int xc,int yc,int r,int start,int end,int c);
  495.                  void    GrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  496.                  void    GrPolyLine(int numpts,int points[][2],int c);
  497.                  void    GrPolygon(int numpts,int points[][2],int c);
  498.  
  499.                   All  primitives  operate  on  the  current  graphics context.  The  last
  500.             argument of these  functions is always the color index to use for the drawing.
  501.             The 'HLine' and  'VLine' primitives  are for drawing  horizontal and  vertical
  502.             lines. They  have been included in the library because they are more efficient
  503.             than the general line drawing provided by 'GrLine'. The ellipse primitives can
  504.             only draw  ellipses with their  major axis  parallel with  either the  X or  Y
  505.             coordinate axis. They take the half X and  Y axis length in the 'xa' and  'ya'
  506.             arguments.  The arc (circle and ellipse) drawing  functions take the start and
  507.             end  angles in  tenths of  degrees (i.e.  meaningful range:  0 ...  3600). The
  508.             angles  are interpreted counter-clockwise  starting from the  positive X axis.
  509.             The polyline and polygon primitives take  the address of an n by  2 coordinate
  510.             array. The X values should be stored in the elements with 0 second  index, and
  511.             the Y values in the elements with a second index value of 1. Coordinate arrays
  512.             passed  to the polygon primitives can either  contain or omit the closing edge
  513.             of the polygon -- the primitive will append it to the list if it is missing.
  514.  
  515.             The following filled primitives are available:
  516.  
  517.             void    GrFilledBox(int x1,int y1,int x2,int y2,int c);
  518.                  void    GrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  519.                  void    GrFilledCircle(int xc,int yc,int r,int c);
  520.                  void    GrFilledEllipse(int xc,int yc,int xa,int ya,int c);
  521.                  void    GrFilledCircleArc(int xc,int yc,int r,int start,int end,int c);
  522.                  void    GrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  523.                  void    GrFilledPolygon(int numpts,int points[][2],int c);
  524.                  void    GrFilledConvexPolygon(int numpts,int points[][2],int c);
  525.  
  526.                   Similarly to the line  drawing, all of  the above primitives operate  on
  527.             the current  graphics context. The 'GrFramedBox' primitive can be used to draw
  528.             motif-like shaded boxes and  "ordinary" framed boxes as well. The 'x1' through
  529.             'y2' coordinates specify the interior  of the box, the border is  outside this
  530.             area. The  primitive  uses five  different colors  for the  interior and  four
  531.             borders of the box which are specified in the 'GrFBoxColors' structure:
  532.  
  533.             typedef struct {
  534.                      int  fbx_intcolor;
  535.                      int  fbx_topcolor;
  536.  
  537.  
  538.  
  539.  
  540.  
  541.                  LIBGRX graphics library user's manual                                                       11
  542.  
  543.  
  544.               int  fbx_rightcolor;
  545.                      int  fbx_bottomcolor;
  546.                      int  fbx_leftcolor;
  547.                  } GrFBoxColors;
  548.  
  549.             The  'GrFilledConvexPolygon' primitive can be used to fill convex polygons. It
  550.             can  also  be used  to  fill some  concave  polygons whose  boundaries  do not
  551.             intersect any horizontal scan line more than twice. All other concave polygons
  552.             have  to  be  filled  with the  (somewhat  less  efficient)  'GrFilledPolygon'
  553.             primitive.  This primitive  can also  be used  to  fill several  disjoint non-
  554.             overlapping polygons in a single operation.
  555.  
  556.             The  current color value of  any pixel in the current  context can be obtained
  557.             with:
  558.  
  559.             int     GrPixel(int x,int y);
  560.  
  561.             Rectangular areas can be  transferred within a context or between  contexts by
  562.             calling:
  563.  
  564.             void    GrBitBlt(GrContext *dest,int x,int y,GrContext *source,int x1,int y1,int x2,int y2,int oper);
  565.  
  566.             The 'oper'  argument should be one  of supported color modes  (write, XOR, OR,
  567.             AND), it will control how the pixels from the source context are combined with
  568.             the pixels in the destination context. If either the source or the destination
  569.             context argument is the NULL pointer then the current context is used for that
  570.             argument.
  571.  
  572.  
  573.             Non-clipping graphics primitives
  574.  
  575.                   There  is a non-clipping version  of some of  the elementary primitives.
  576.             These are somewhat more efficient  than the regular versions. These are  to be
  577.             used only  in situations when it is absolutely certain that no drawing will be
  578.             performed  beyond the boundaries of the current context. Otherwise the program
  579.             will almost certainly crash! The reason for including these functions  is that
  580.             they are somewhat  more efficient  than the regular,  clipping versions.  ALSO
  581.             NOTE: These  function do not check  for conflicts with the  mouse cursor. (See
  582.             the explanation about  the mouse cursor handling later in  this document.) The
  583.             list of the supported non-clipping primitives:
  584.  
  585.             void    GrPlotNC(int x,int y,int c);
  586.                  void    GrLineNC(int x1,int y1,int x2,int y2,int c);
  587.                  void    GrHLineNC(int x1,int x2,int y,int c);
  588.                  void    GrVLineNC(int x,int y1,int y2,int c);
  589.                  void    GrBoxNC(int x1,int y1,int x2,int y2,int c);
  590.                  void    GrFilledBoxNC(int x1,int y1,int x2,int y2,int c);
  591.                  void    GrFramedBoxNC(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  592.                  void    GrBitBltNC(GrContext *dst,int x,int y,GrContext *src,int x1,int y1,int x2,int y2,int oper);
  593.                  int     GrPixelNC(int x,int y);
  594.  
  595.  
  596.  
  597.  
  598.  
  599.             LIBGRX graphics library user's manual                                       12
  600.  
  601.  
  602.           Customized line drawing
  603.  
  604.                   The basic  line drawing graphics primitives  described previously always
  605.             draw continuous lines which are one pixel wide. There is another group of line
  606.             drawing functions which can be used to draw wide and/or patterned lines. These
  607.             functions  have similar parameter passing  conventions as the  basic ones with
  608.             one  difference: instead of the color  value a pointer to  a structure of type
  609.             'GrLineOption' has to be passed to them. The definition  of the 'GrLineOption'
  610.             structure:
  611.  
  612.             typedef struct {
  613.                      int  lno_color;                     /* color used to draw line */
  614.                      int  lno_width;                     /* width of the line */
  615.                      int  lno_pattlen;                   /* length of the dash pattern */
  616.                      unsigned char *lno_dashpat;         /* draw/nodraw pattern */
  617.                  } GrLineOption;
  618.  
  619.             The  'lno_pattlen'  structure  element  should  be  equal  to  the  number  of
  620.             alternating draw  -- no draw section length values  in the array pointed to by
  621.             the 'lno_dashpat' element.  The dash pattern array is assumed  to begin with a
  622.             drawn section. If the  pattern length is  equal to zero  a continuous line  is
  623.             drawn. The available custom line drawing primitives:
  624.  
  625.           void    GrCustomLine(int x1,int y1,int x2,int y2,GrLineOption *o);
  626.                  void    GrCustomBox(int x1,int y1,int x2,int y2,GrLineOption *o);
  627.                  void    GrCustomCircle(int xc,int yc,int r,GrLineOption *o);
  628.                  void    GrCustomEllipse(int xc,int yc,int xa,int ya,GrLineOption *o);
  629.                  void    GrCustomCircleArc(int xc,int yc,int r,int start,int end,GrLineOption *o);
  630.                  void    GrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLineOption *o);
  631.                  void    GrCustomPolyLine(int numpts,int points[][2],GrLineOption *o);
  632.                  void    GrCustomPolygon(int numpts,int points[][2],GrLineOption *o);
  633.  
  634.  
  635.             Pattern filled graphics primitives
  636.  
  637.                   The library  also supports a pattern filled  version of the basic filled
  638.             primitives  described above.  These functions  have similar  parameter passing
  639.             conventions as the basic ones with  one difference: instead of the color value
  640.             a  pointer to  an union  of type  'GrPattern' has  to be  passed to  them. The
  641.             'GrPattern' union  can contain either a  bitmap or a pixmap  fill pattern. The
  642.             first  integer slot  in the  union determines  which type  it is.  Bitmap fill
  643.             patterns  are  rectangular  arrays of  bits,  each  set  bit representing  the
  644.             foreground  color of  the fill operation,  and each zero  bit representing the
  645.             background. Both the foreground and background colors can be combined with any
  646.             of  the   supported  logical  operations.   Bitmap  fill  patterns   have  one
  647.             restriction: their width must be  eight pixels. Pixmap fill patterns are  very
  648.             similar to contexts,  the data is  transferred to the  filled primitive  using
  649.             'BitBlt' operations. The relevant structure declarations (from "grx.h"):
  650.  
  651.             /*
  652.                   * BITMAP: a mode independent way to specify a fill pattern of two
  653.  
  654.  
  655.  
  656.  
  657.  
  658.                  LIBGRX graphics library user's manual                                                       13
  659.  
  660.  
  661.            *   colors. It is always 8 pixels wide (1 byte per scan line), its
  662.                   *   height is user-defined. SET THE TYPE FLAG TO ZERO!!!
  663.                   */
  664.                  typedef struct {
  665.                      int  bmp_ispixmap;                  /* type flag for pattern union */
  666.                      int  bmp_height;                    /* bitmap height */
  667.                      unsigned char *bmp_data;            /* pointer to the bit pattern */
  668.                      int  bmp_fgcolor;                   /* foreground color for fill */
  669.                      int  bmp_bgcolor;                   /* background color for fill */
  670.                      int  bmp_memflags;                  /* set if dynamically allocated */
  671.                  } GrBitmap;
  672.  
  673.                  /*
  674.                   * PIXMAP: a fill pattern stored in a layout identical to the video RAM
  675.                   *   for filling using 'bitblt'-s. It is mode dependent, typically one
  676.                   *   of the library functions is used to build it. KEEP THE TYPE FLAG
  677.                   *   NONZERO!!!
  678.                   */
  679.                  typedef struct {
  680.                      int  pxp_ispixmap;                  /* type flag for pattern union */
  681.                      int  pxp_width;                     /* pixmap width (in pixels)  */
  682.                      int  pxp_height;                    /* pixmap height (in pixels) */
  683.                      int  pxp_oper;                      /* bitblt mode (SET, OR, XOR, AND) */
  684.                      GrVidRAM pxp_source;                /* source context for fill */
  685.                  } GrPixmap;
  686.  
  687.                  /*
  688.                   * Fill pattern union -- can either be a bitmap or a pixmap
  689.                   */
  690.                  typedef union {
  691.                      int      gp_ispixmap;               /* nonzero for pixmaps */
  692.                      GrBitmap gp_bitmap;                 /* fill bitmap */
  693.                      GrPixmap gp_pixmap;                 /* fill pixmap */
  694.                  } GrPattern;
  695.  
  696.                  #define gp_bmp_data                     gp_bitmap.bmp_data
  697.                  #define gp_bmp_height                   gp_bitmap.bmp_height
  698.                  #define gp_bmp_fgcolor                  gp_bitmap.bmp_fgcolor
  699.                  #define gp_bmp_bgcolor                  gp_bitmap.bmp_bgcolor
  700.  
  701.                  #define gp_pxp_width                    gp_pixmap.pxp_width
  702.                  #define gp_pxp_height                   gp_pixmap.pxp_height
  703.                  #define gp_pxp_oper                     gp_pixmap.pxp_oper
  704.                  #define gp_pxp_source                   gp_pixmap.pxp_source
  705.  
  706.             Bitmap  patterns can  be easily  built from  initialized character  arrays and
  707.             static structures  by the C compiler,  thus no special support  is included in
  708.             the library for creating  them. The only action required  from the application
  709.             program  might be  changing the  foreground and  background colors  as needed.
  710.             Pixmap patterns  are more difficult to  build as they replicate  the layout of
  711.             the video  memory which changes for different video modes. For this reason the
  712.  
  713.  
  714.  
  715.  
  716.  
  717.             LIBGRX graphics library user's manual                                       14
  718.  
  719.  
  720.           library  provides three  functions  to  create  pixmap  patterns  in  a  mode-
  721.             independent way:
  722.  
  723.             GrPattern *GrBuildPixmap(char *pixels,int w,int h,GrColorTableP colors);
  724.                  GrPattern *GrBuildPixmapFromBits(char *bits,int w,int h,int fgc,int bgc);
  725.                  GrPattern *GrConvertToPixmap(GrContext *src);
  726.  
  727.             'GrBuildPixmap' build  a pixmap from a  two dimensional ('w' by  'h') array of
  728.             characters. The  elements in this  array are  used as indices  into the  color
  729.             table specified with the  argument 'colors'. (This means that  pixmaps created
  730.             this way can use at most 256 colors.) The color table pointer:
  731.  
  732.             typedef int *GrColorTableP;
  733.  
  734.             should  point to an array of integers with  the first element being the number
  735.             of  colors in  the table and  the color  indices themselves  starting with the
  736.             second element.  NOTE: any color modifiers  (GrXOR, GrOR, GrAND) OR-ed  to the
  737.             elements of the color table are ignored.
  738.  
  739.             The 'GrBuildPixmapFromBits' function builds a pixmap fill pattern  from bitmap
  740.             data. It  is useful if the  width of the bitmap  pattern is not  eight as such
  741.             bitmap patterns can not be used to build a 'GrBitmap' structure.
  742.  
  743.             The  'GrConvertToPixmap' function converts a graphics context to a pixmap fill
  744.             pattern. It  is useful when the  pattern can be created  with graphics drawing
  745.             operations.  NOTE: the  pixmap  pattern and  the  original context  share  the
  746.             drawing RAM, thus if the context is redrawn the fill pattern changes as well. 
  747.  
  748.                   Fill patterns which were built by library routines can be destroyed when
  749.             no longer needed (i.e. the space occupied by them can be freed) by calling:
  750.  
  751.             void    GrDestroyPattern(GrPattern *p);
  752.  
  753.             NOTE: when pixmap  fill patterns  converted from contexts  are destroyed,  the
  754.             drawing RAM is not freed. It is  freed when the original context is destroyed.
  755.             Fill patterns built by the application have to be destroyed by the application
  756.             as well (if this is needed). 
  757.  
  758.                   The list of supported pattern filled graphics primitives is shown below.
  759.             These  functions are  very similar  to their  solid filled  counterparts, only
  760.             their last argument is different:
  761.  
  762.             void    GrPatternFilledPlot(int x,int y,GrPattern *p);
  763.                  void    GrPatternFilledLine(int x1,int y1,int x2,int y2,GrPattern *p);
  764.                  void    GrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
  765.                  void    GrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
  766.                  void    GrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
  767.                  void    GrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,GrPattern *p);
  768.                  void    GrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrPattern *p);
  769.                  void    GrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p);
  770.                  void    GrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
  771.  
  772.  
  773.  
  774.  
  775.  
  776.             LIBGRX graphics library user's manual                                       15
  777.  
  778.  
  779.           Strictly  speaking the  plot and  line functions  in the  above group  are not
  780.             filled, but they have been included here for convenience.
  781.  
  782.  
  783.             Patterned line drawing
  784.  
  785.                   The custom line drawing  functions introduced above also have  a version
  786.             when the  drawn sections can be filled with a (pixmap or bitmap) fill pattern.
  787.             To achieve  this these functions  must be  passed both a  custom line  drawing
  788.             option  ('GrLineOption' structure)  and  a fill  pattern ('GrPattern'  union).
  789.             These two have been combined into the 'GrLinePattern' structure:
  790.  
  791.             typedef struct {
  792.                      GrPattern     *lnp_pattern;         /* fill pattern */
  793.                      GrLineOption  *lnp_option;          /* width + dash pattern */
  794.                  } GrLinePattern;
  795.  
  796.             All patterned line drawing functions take a pointer to this structure as their
  797.             last argument. The list of available functions:
  798.  
  799.             void    GrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  800.                  void    GrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  801.                  void    GrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
  802.                  void    GrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
  803.                  void    GrPatternedCircleArc(int xc,int yc,int r,int start,int end,GrLinePattern *lp);
  804.                  void    GrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLinePattern *lp);
  805.                  void    GrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
  806.                  void    GrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
  807.  
  808.  
  809.             Text drawing
  810.  
  811.                   The  library supports  loadable bit-mapped  (i.e. not  scalable!) fonts.
  812.             Some of  these fonts were converted  from VGA BIOS fonts and  fonts on utility
  813.             diskettes  coming with VGA  cards. These fonts  have all  256 characters. Some
  814.             additional fonts were converted from fonts in the MIT X11  distribution. These
  815.             have  a variable number of  characters, some support  all 256 character codes,
  816.             some only the  printable ASCII codes. Fonts also have  family names, which are
  817.             used in  a font lookup  procedure supported  by the library  (see later).  The
  818.             following font families are included in the distribution:
  819.  
  820.  
  821.  
  822.  
  823.  
  824.             LIBGRX graphics library user's manual                                       16
  825.  
  826.  
  827.                Font file name:         Family:     Description:
  828.  
  829.                   pc<W>x<H>[t].fnt        pc    BIOS font, fixed 
  830.                   xm<W>x<H>[b][i].fnt     X_misc      X11, fixed, miscellaneous group  
  831.                   char<H>[b][i].fnt char  X11, proportional, charter family
  832.                   cour<H>[b][i].fnt cour  X11, fixed, courier
  833.                   helve<H>[b][i].fnt      helve X11, proportional, helvetica 
  834.                   lucb<H>[b][i].fnt lucb  X11, proportional, lucida bright
  835.                   lucs<H>[b][i].fnt lucs  X11, proportional, lucida sans serif
  836.                   luct<H>[b][i].fnt       luct  X11, fixed, lucida typewriter
  837.                   ncen<H>[b][i].fnt ncen  X11, proportional, new century schoolbook
  838.                   symb<H>.fnt             symbol      X11,  proportional,  greek  letters,
  839.             symbols
  840.                   tms<H>[b][i].fnt        times X11, proportional, times
  841.  
  842.             In the font  names <W> means the  font width, <H>  the font height. Many  font
  843.             families  have bold and/or italic  variants. The files  containing these fonts
  844.             contain a  'b' and/or 'i' character  in their name just  before the extension.
  845.             Additionally,  the strings  "_bold" and/or  "_ital" are  appended to  the font
  846.             family names. Some of the pc BIOS  fonts come in thin formats also, these  are
  847.             denoted by a  't' in their file  names and the string "_thin"  in their family
  848.             names. 
  849.  
  850.             NOTE:  the basic libgrx  distribution ("cbgrx101.zip") contains  only the full
  851.             "pc", "courier",  "helve", "symbol"  and  "times" font  families and  selected
  852.             sizes  from the "X_misc" family. (Because of archive size considerations!) The
  853.             full  compliment   of  fonts   can  be  found   in  the  archive   file  named
  854.             "cbgrxfnt.zip", which should  be available from the same site  where the basic
  855.             library was obtained from.
  856.  
  857.                   Fonts are loaded  with the 'GrLoadFont' function. If  the font file name
  858.             starts  with  any path  separator  character  or character  sequence  ('<drive
  859.             letter>:',  '/'  or  '\') then  it  is  loaded from  the  specified directory,
  860.             otherwise the font  is loaded from the default font path. The font path can be
  861.             set up with the 'GrSetFontPath' function. If the font path is not set then the
  862.             value  of the  'GRXFONT' environment  variable is  used as  the font  path. If
  863.             'GrLoadFont'  is called again with the name  of an already loaded font then it
  864.             will  return a pointer  to the result  of the first loading.  The special font
  865.             names "@:pc8x8.fnt", "@:pc8x14.fnt" and "@:pc8x16.fnt" will cause 'GrLoadFont'
  866.             to load the font from  the BIOS of the graphics card of the  PC (provided that
  867.             it has the desired  font). Alternatively, 'GrLoadBIOSFont' can also  be called
  868.             to load  a  font  which resides  in  the BIOS  of  the display  adapter.  (The
  869.             difference is that 'GrLoadFont' will look at the disk as well if the BIOS does
  870.             not have the font. For example: EGA-s don't have a 16 row font in their BIOS.)
  871.             Both font loading  routines return NULL if  the font was  not found. When  not
  872.             needed  any more,  fonts can be  unloaded (i.e.  the storage  occupied by them
  873.             freed)  by  calling  'GrUnloadFont'.  The  prototype  declarations  for  these
  874.             functions:
  875.  
  876.             GrFont *GrLoadFont(char *name);
  877.                  GrFont *GrLoadBIOSFont(char *name);
  878.  
  879.  
  880.  
  881.  
  882.  
  883.                  LIBGRX graphics library user's manual                                                       17
  884.  
  885.  
  886.           void    GrUnloadFont(GrFont *font);
  887.                  void    GrSetFontPath(char *path);
  888.  
  889.                   The 'GrFont' structure is actually a font header, the real  font data is
  890.             right  next to  this header  in memory, but  it is  typically hidden  from the
  891.             application  program. If needed, the include file "grxfont.h" can provide more
  892.             details. The 'GrFont' structure:
  893.  
  894.             typedef struct {
  895.                      short   fnt_width;                  /* width (average for proportional) */
  896.                      short   fnt_height;                 /* font height */
  897.                      short   fnt_minchar;                /* lowest character code in font */
  898.                      short   fnt_maxchar;                /* highest character code in font */
  899.                      short   fnt_isfixed;                /* nonzero if fixed font */
  900.                      short   fnt_internal;               /* nonzero if BIOS font */
  901.                      short   fnt_baseline;               /* baseline from top of font */
  902.                      short   fnt_undwidth;               /* underline width (at bottom) */
  903.                      char    fnt_name[GR_NAMEWIDTH];     /* font file name (w/o path) */
  904.                      char    fnt_family[GR_NAMEWIDTH];   /* font family name */
  905.                  } GrFont;
  906.  
  907.                   There  is  a function:  'GrFindBestFont'  which returns  the  font which
  908.             matches  best  a desired  size.  (Best  match: not  bigger,  but  as close  as
  909.             possible).  The application can  specify whether it  wants 'GrFindBestFont' to
  910.             find  the best  match using fonts  in their  original sizes  only, or possibly
  911.             enlarged (with  the value of the  'magnify' argument -- 0:  no, nonzero: yes).
  912.             'GrFindBestFont'  also takes a string argument which specifies the font family
  913.             from which to select the font. The string can specify  several family patterns
  914.             separated  by the  ':' character.  Each pattern  can contain  the '?'  and '*'
  915.             wildcard characters which work the  usual way (in UNIX sense --  i.e. "X*ital"
  916.             will match "X_misc_ital", but not "X_misc_bold"..).
  917.  
  918.             GrTextOption *GrFindBestFont(int width,int height,int magnify,char *family,GrTextOption *where);
  919.  
  920.             The 'GrTextOption' structure specifies how to draw a character string:
  921.  
  922.             typedef struct {
  923.                      GrFont *txo_font;                   /* font to be used */
  924.                      int     txo_xmag;                   /* X magnification */
  925.                      int     txo_ymag;                   /* Y magnification */
  926.                      union {
  927.                          int v;                          /* color when no attributes */
  928.                          GrColorTableP p;                /* ptr to color table otherwise */
  929.                      } txo_fgcolor,txo_bgcolor;          /* foreground, background */
  930.                      char    txo_direct;                 /* direction */
  931.                      char    txo_xalign;                 /* X alignment */
  932.                      char    txo_yalign;                 /* Y alignment */
  933.                      char    txo_chrtype;                /* character type */
  934.                  } GrTextOption;
  935.  
  936.  
  937.  
  938.  
  939.  
  940.             LIBGRX graphics library user's manual                                       18
  941.  
  942.  
  943.           The font can be enlarged independently in the X and  Y directions, ('txo_xmag'
  944.             and  'txo_ymag' slots  --  values:  1  and up)  the  text  can be  rotated  in
  945.             increments  of  90  degrees ('txo_direct'),  alignments  can  be  set in  both
  946.             directions ('txo_xalign'  and 'txo_yalign'), and separate  fore and background
  947.             colors can be specified. The accepted text direction values:
  948.  
  949.             #define GR_TEXT_RIGHT           0       /* normal */
  950.                  #define GR_TEXT_DOWN            1       /* downward */
  951.                  #define GR_TEXT_LEFT            2       /* upside down, right to left */
  952.                  #define GR_TEXT_UP              3       /* upward */
  953.                  #define GR_TEXT_DEFAULT         GR_TEXT_RIGHT
  954.  
  955.             The accepted horizontal and vertical alignment option values:
  956.  
  957.             #define GR_ALIGN_LEFT           0       /* X only */
  958.                  #define GR_ALIGN_TOP            0       /* Y only */
  959.                  #define GR_ALIGN_CENTER         1       /* X, Y */
  960.                  #define GR_ALIGN_RIGHT          2       /* X only */
  961.                  #define GR_ALIGN_BOTTOM         2       /* Y only */
  962.                  #define GR_ALIGN_BASELINE       3       /* Y only */
  963.                  #define GR_ALIGN_DEFAULT        GR_ALIGN_LEFT
  964.  
  965.             Text strings can be of three different types: one character per byte (i.e. the
  966.             usual C  character string, this is the default), one character per 16-bit word
  967.             (suitable  for  fonts with  a  large number  of  characters),  and a  PC-style
  968.             character-attribute pair. In the  last case the 'GrTextOption' structure  must
  969.             contain a pointer to  a color table of size 16 (fg color  bits in attrib) or 8
  970.             (bg color  bits). (The color table format  is explained in more  detail in the
  971.             previous section explaining the methods to build fill patterns.) The supported
  972.             text types:
  973.  
  974.             #define GR_BYTE_TEXT            0       /* one byte per character */
  975.                  #define GR_WORD_TEXT            1       /* two bytes per character */
  976.                  #define GR_ATTR_TEXT            2       /* char w/ PC style attribute byte */
  977.  
  978.             The  PC-style  attribute text  uses the  same  layout (first  byte: character,
  979.             second: attributes) and bitfields  as the text mode screen on the PC. The only
  980.             difference  is that the  'blink' bit is  not supported (it would  be very time
  981.             consuming -- the PC text mode does it with hardware support). This bit is used
  982.             instead to control the  underlined display of characters. For  convenience the
  983.             following attribute manipulation macros have been declared in "grx.h":
  984.  
  985.             #define GR_BUILD_ATTR(fgcolor,bgcolor,underline)  \
  986.                      ((fgcolor) & 15) | (((bgcolor) & 7) << 4) | (((underline) & 1) << 7))
  987.                  #define GR_ATTR_FGCOLOR(attr)   ((attr) & 15)
  988.                  #define GR_ATTR_BGCOLOR(attr)   (((attr) >> 4) & 7)
  989.                  #define GR_ATTR_UNDERLINE(attr) (((attr) >> 7) & 1)
  990.  
  991.             Text strings of  the types 'GR_BYTE_TEXT' and 'GR_WORD_TEXT" can also be drawn
  992.             underlined. This is  controlled by OR-ing the  constant 'GR_UNDERLINE_TEXT' to
  993.             the foreground color value:
  994.  
  995.  
  996.  
  997.  
  998.  
  999.                  LIBGRX graphics library user's manual                                                       19
  1000.  
  1001.  
  1002.           #define GR_UNDERLINE_TEXT                 (GrXOR << 6)
  1003.  
  1004.                   After the  application  initializes a  text  option structure  with  the
  1005.             desired values it can call one of the following two text drawing functions:
  1006.  
  1007.             void    GrDrawChar(int chr,int x,int y,GrTextOption *opt);
  1008.                  void    GrDrawString(char *text,int length,int x,int y,GrTextOption *opt);
  1009.  
  1010.             NOTE: text drawing is fastest  when the font is not magnified, it  is drawn in
  1011.             the 'normal' direction, and the character does not have to be clipped. It this
  1012.             case the library can  use the appropriate low-level  video RAM access  routine
  1013.             (see  "INTERNAL.DOC" for more  details), while in  any other case  the text is
  1014.             drawn   pixel-by-pixel  (or   rectangle-by-rectangle   if  enlarged)   by  the
  1015.             higher-level code.
  1016.  
  1017.                   The function 'GrTextXY' is provided for compatibility with the  original
  1018.             256 color DJGPP graphics library. It draws the text in the standard direction,
  1019.             unmagnified, and  using the 16 row  BIOS font on VGA-s  or the 14  row font on
  1020.             EGA-s. 
  1021.  
  1022.             void    GrTextXY(int x,int y,char *text,int fg,int bg);
  1023.  
  1024.                   The  size of a  font, a character  or a text  string can be  obtained by
  1025.             calling  one  of  the following  functions.  These  functions  also take  into
  1026.             consideration  the  magnification and  text  direction specified  in  the text
  1027.             option structure passed to them.
  1028.  
  1029.             int     GrFontHeight(GrTextOption *opt);
  1030.                  int     GrFontWidth(GrTextOption *opt);
  1031.                  int     GrCharWidth(int chr,GrTextOption *opt);
  1032.                  int     GrCharHeight(int chr,GrTextOption *opt);
  1033.                  int     GrStringWidth(char *text,int length,GrTextOption *opt);
  1034.                  int     GrStringHeight(char *text,int length,GrTextOption *opt);
  1035.  
  1036.                   The 'GrTextRegion' structure and its associated functions can be used to
  1037.             implement  a fast  (as much as  possible in  graphics modes)  rectangular text
  1038.             window using a fixed font. Clipping for such windows is done in character size
  1039.             increments  instead of  pixels (i.e.  no partial  characters are  drawn). Only
  1040.             fixed  fonts can be  used in their  natural size. 'GrDumpText'  will cache the
  1041.             code of the drawn characters in the buffer pointed to by the 'backup' slot (if
  1042.             it  is non-NULL)  and  will draw  a  character only  if  the previously  drawn
  1043.             character in  that grid element is different. This can speed up text scrolling
  1044.             significantly in  graphics modes.  The supported  text types are  the same  as
  1045.             above.
  1046.  
  1047.             typedef struct {
  1048.                      GrFont *txr_font;                   /* font to be used */
  1049.                      char   *txr_buffer;                 /* pointer to text buffer */
  1050.                      char   *txr_backup;                 /* optional backup buffer */
  1051.                      int     txr_xpos;                   /* upper left corner X coordinate */
  1052.                      int     txr_ypos;                   /* upper left corner Y coordinate */
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.                  LIBGRX graphics library user's manual                                                       20
  1059.  
  1060.  
  1061.               int     txr_width;                  /* width of area in chars */
  1062.                      int     txr_height;                 /* height of area in chars */
  1063.                      int     txr_lineoffset;             /* offset in buffer(s) between lines */
  1064.                      union {
  1065.                          int v;                          /* color when no attributes */
  1066.                          GrColorTableP p;                /* ptr to color table otherwise */
  1067.                      } txr_fgcolor,txr_bgcolor;          /* foreground, background */
  1068.                      char    txr_chrtype;                /* character type (see above) */
  1069.                  } GrTextRegion;
  1070.  
  1071.                  void    GrDumpChar(int chr,int col,int row,GrTextRegion *r);
  1072.                  void    GrDumpText(int col,int row,int wdt,int hgt,GrTextRegion *r);
  1073.                  void    GrDumpTextRegion(GrTextRegion *r);
  1074.  
  1075.             The  'GrDumpTextRegion'   function  outputs  the  whole   text  region,  while
  1076.             'GrDumpText'  draws only a user-specified part of it. 'GrDumpChar' updates the
  1077.             character  in the  buffer at  the specified  location with  the new  character
  1078.             passed  to it as  argument and then draws  the new character  on the screen as
  1079.             well. 
  1080.  
  1081.  
  1082.             Drawing in user coordinates
  1083.  
  1084.                  There is a second set  of the graphics primitives which operates  in user
  1085.             coordinates.  Every context has a user to screen coordinate mapping associated
  1086.             with  it.  An   application  specifies   the  user  window   by  calling   the
  1087.             'GrSetUserWindow' function.
  1088.  
  1089.             void    GrSetUserWindow(int x1,int y1,int x2,int y2);
  1090.  
  1091.             A call to  this function it  in fact specifies  the virtual coordinate  limits
  1092.             which  will be mapped onto  the current context regardless  of the size of the
  1093.             context. For example, the call:
  1094.  
  1095.             GrSetUserWindow(0,0,11999,8999);
  1096.  
  1097.             tells the  library that the program  will perform its drawing  operations in a
  1098.             coordinate system X:0...11999 (width = 12000)  and Y:0...8999 (height = 9000).
  1099.             This  coordinate  range will  be mapped  onto the  total  area of  the current
  1100.             context. The virtual coordinate system can also be shifted. For example:
  1101.  
  1102.             GrSetUserWindow(5000,2000,16999,10999);
  1103.  
  1104.             The user coordinates can even be used to turn the usual left-handed coordinate
  1105.             system (0:0  corresponds to the upper left corner)  to a right handed one (0:0
  1106.             corresponds to the bottom left corner) by calling:
  1107.  
  1108.             GrSetUserWindow(0,8999,11999,0);
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.             LIBGRX graphics library user's manual                                       21
  1115.  
  1116.  
  1117.                The library also  provides three utility functions for the  query of the
  1118.             current user coordinate limits  and for converting user coordinates  to screen
  1119.             coordinates and vice versa.
  1120.  
  1121.             void    GrGetUserWindow(int *x1,int *y1,int *x2,int *y2);
  1122.                  void    GrGetScreenCoord(int *x,int *y);
  1123.                  void    GrGetUserCoord(int *x,int *y);
  1124.  
  1125.                   If  an  application wants  to  take  advantage  of the  user  to  screen
  1126.             coordinate mapping it  has to use  the user  coordinate version  of
  1127.           the graphics  primitives. These  have exactly the  same parameter
  1128.           passing  conventions  as  their  screen  coordinate counterparts.
  1129.           NOTE: the  user  coordinate  system is  not  initialized  by  the
  1130.           library! The  application has  to set  up its  coordinate mapping
  1131.           before  calling any of  the use  coordinate drawing  functions --
  1132.           otherwise the  program will  almost  certainly exit  (in a  quite
  1133.           ungraceful  fashion) with a 'division by zero' error. The list of
  1134.           supported user coordinate drawing functions:
  1135.  
  1136.           void    GrUsrPlot(int x,int y,int c);
  1137.                  void    GrUsrLine(int x1,int y1,int x2,int y2,int c);
  1138.                  void    GrUsrHLine(int x1,int x2,int y,int c);
  1139.                  void    GrUsrVLine(int x,int y1,int y2,int c);
  1140.                  void    GrUsrBox(int x1,int y1,int x2,int y2,int c);
  1141.                  void    GrUsrFilledBox(int x1,int y1,int x2,int y2,int c);
  1142.                  void    GrUsrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  1143.                  void    GrUsrCircle(int xc,int yc,int r,int c);
  1144.                  void    GrUsrEllipse(int xc,int yc,int xa,int ya,int c);
  1145.                  void    GrUsrCircleArc(int xc,int yc,int r,int start,int end,int c);
  1146.                  void    GrUsrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  1147.                  void    GrUsrFilledCircle(int xc,int yc,int r,int c);
  1148.                  void    GrUsrFilledEllipse(int xc,int yc,int xa,int ya,int c);
  1149.                  void    GrUsrFilledCircleArc(int xc,int yc,int r,int start,int end,int c);
  1150.                  void    GrUsrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  1151.                  void    GrUsrPolyLine(int numpts,int points[][2],int c);
  1152.                  void    GrUsrPolygon(int numpts,int points[][2],int c);
  1153.                  void    GrUsrFilledConvexPolygon(int numpts,int points[][2],int c);
  1154.                  void    GrUsrFilledPolygon(int numpts,int points[][2],int c);
  1155.                  int     GrUsrPixel(int x,int y);
  1156.  
  1157.                  void    GrUsrCustomLine(int x1,int y1,int x2,int y2,GrLineOption *o);
  1158.                  void    GrUsrCustomBox(int x1,int y1,int x2,int y2,GrLineOption *o);
  1159.                  void    GrUsrCustomCircle(int xc,int yc,int r,GrLineOption *o);
  1160.                  void    GrUsrCustomEllipse(int xc,int yc,int xa,int ya,GrLineOption *o);
  1161.                  void    GrUsrCustomCircleArc(int xc,int yc,int r,int start,int end,GrLineOption *o);
  1162.                  void    GrUsrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLineOption *o);
  1163.                  void    GrUsrCustomPolyLine(int numpts,int points[][2],GrLineOption *o);
  1164.                  void    GrUsrCustomPolygon(int numpts,int points[][2],GrLineOption *o);
  1165.  
  1166.                  void    GrUsrPatternedPlot(int x,int y,GrPattern *p);
  1167.                  void    GrUsrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.                  LIBGRX graphics library user's manual                                                       22
  1174.  
  1175.  
  1176.           void    GrUsrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  1177.                  void    GrUsrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
  1178.                  void    GrUsrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
  1179.                  void    GrUsrPatternedCircleArc(int xc,int yc,int r,int start,int end,GrLinePattern *lp);
  1180.                  void    GrUsrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLinePattern *lp);
  1181.                  void    GrUsrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
  1182.                  void    GrUsrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
  1183.  
  1184.                  void    GrUsrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
  1185.                  void    GrUsrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
  1186.                  void    GrUsrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
  1187.                  void    GrUsrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,GrPattern *p);
  1188.                  void    GrUsrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrPattern *p);
  1189.                  void    GrUsrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p);
  1190.                  void    GrUsrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
  1191.  
  1192.                  GrTextOption *GrUsrFindBestFont(int width,int height,int magnify,char *family,GrTextOption *where);
  1193.                  void    GrUsrDrawChar(int chr,int x,int y,GrTextOption *opt);
  1194.                  void    GrUsrDrawString(char *text,int length,int x,int y,GrTextOption *opt);
  1195.                  void    GrUsrTextXY(int x,int y,char *text,int fg,int bg);
  1196.  
  1197.  
  1198.             Graphics cursors
  1199.  
  1200.                   The library provides support for the creation and usage of  an unlimited
  1201.             number of  graphics cursors.  An application  can  use these  cursors for  any
  1202.             purpose. Cursors  always save the area they occupy before they are drawn. When
  1203.             moved or  erased they  restore  this area.  As a  general  rule of  thumb,  an
  1204.             application should erase a cursor before making changes to an area it occupies
  1205.             and  redraw the  cursor  after finishing  the  drawing. All  cursor and  mouse
  1206.             related  declaration are in the  include file "mousex.h".  Cursors are created
  1207.             with the 'GrBuildCursor' function:
  1208.  
  1209.             GrCursor *GrBuildCursor(char *data,int w,int h,int xo,int yo,GrColorTableP c);
  1210.  
  1211.             The 'data',  'w' (=width), 'h' (=height) and 'c' (= color table) arguments are
  1212.             similar  to  the   arguments  of   the  pixmap   building  library   function:
  1213.             'GrBuildPixmap'. (See  that paragraph for  a more  detailed explanation.)  The
  1214.             only difference is that  the pixmap data is interpreted  slightly differently:
  1215.             any  pixel  with value  zero  is  taken as  a  "transparent"  pixel, i.e.  the
  1216.             background will show  through the cursor pattern at that  pixel. A pixmap data
  1217.             byte with value = 1 will refer to the first color in the table, and so on. The
  1218.             'xo' (= X offset) and  'yo' (= Y offset) arguments specify  the position (from
  1219.             the top left corner of  the cursor pattern)  of the cursor's  "hot point". The
  1220.             'GrCursor' data structure:
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.                  LIBGRX graphics library user's manual                                                       23
  1227.  
  1228.  
  1229.           typedef struct {
  1230.                      GrVidRAM  cr_andmask;               /* cursor bitmap to AND */
  1231.                      GrVidRAM  cr_ormask;                /* cursor bitmap to OR */
  1232.                      GrVidRAM  cr_work;                  /* work area */
  1233.                      GrVidRAM  cr_save;                  /* screen save area */
  1234.                      int   cr_xcord,cr_ycord;            /* cursor position on screen */
  1235.                      int   cr_xsize,cr_ysize;            /* cursor size */
  1236.                      int   cr_xoffs,cr_yoffs;            /* LU corner to hot point offset */
  1237.                      int   cr_xwork,cr_ywork;            /* save/work area sizes */
  1238.                      int   cr_xwpos,cr_ywpos;            /* save/work area position on screen */
  1239.                      int   cr_displayed;                 /* set if displayed */
  1240.                  } GrCursor;
  1241.  
  1242.             is typically  not used (i.e. read  or changed) by the  application program, it
  1243.             should  just  pass pointers  to these  structures  to the  appropriate library
  1244.             functions. Other cursor manipulation functions:
  1245.  
  1246.             void GrDestroyCursor(GrCursor *cursor);
  1247.                  void GrDisplayCursor(GrCursor *cursor);
  1248.                  void GrEraseCursor(GrCursor *cursor);
  1249.                  void GrMoveCursor(GrCursor *cursor,int x,int y);
  1250.  
  1251.  
  1252.             Mouse event handling
  1253.  
  1254.                   All mouse  services  need  the presence  of  a mouse  and  an  installed
  1255.             Microsoft compatible mouse  driver. An application can test whether a mouse is
  1256.             available by calling the function:
  1257.  
  1258.             int  MouseDetect(void);
  1259.  
  1260.             which will  return zero  if no  mouse (or mouse  driver) is  present, non-zero
  1261.             otherwise. If the mouse is present the  application may decide if it wants  to
  1262.             use  the  mouse  in  interrupt-driven  or polled  mode.  The  polled  mode  is
  1263.             compatible with previous releases of DJGPP and the 256 color graphics library,
  1264.             it  uses the mouse  driver interrupts (INT  33h) to query  the mouse about its
  1265.             position and  buttons. This  method  is adequate  if the  program  can do  the
  1266.             polling in  a tight enough loop.  If the program does  lengthy computations in
  1267.             the background  during which a  "frozen" mouse  and the loss  of mouse  button
  1268.             presses would be  disturbing it has  to use the  interrupt driven method.  For
  1269.             this a  patched version of  GO32 is needed --  a GO32 version  dated after the
  1270.             middle of April  1992 should work. The interrupt  driven mouse event mechanism
  1271.             uses an event  queue library  (described in the  document "EVENTS.DOC")  which
  1272.             stores all  user interaction  events (mouse  presses and  keyboard hits) in  a
  1273.             queue,  timestamped, in  the  order of  occurrence.  The disadvantage  of  the
  1274.             interrupt-driven  mouse event mechanism is that it  may be harder to debug. To
  1275.             select between the two modes the following function needs to be called:
  1276.  
  1277.             void MouseEventMode(int use_interrupts);
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.             LIBGRX graphics library user's manual                                       24
  1284.  
  1285.  
  1286.           If the  'use_interrupts' parameter is zero  the mouse is put  into polled mode
  1287.             (this  is  the  default),  otherwise  it  will  work  interrupt-driven.  After
  1288.             selecting the mode, the mouse can be initialized by calling:
  1289.  
  1290.             void MouseInit(void);
  1291.  
  1292.             It  is   not  necessary  to  call   this  function  as  the   first  call  the
  1293.             'MouseGetEvent'  (see later)  function will  also perform  the initialization.
  1294.             However,  if the mouse  event mode is  changed after using  'MouseGetEvent', a
  1295.             call to 'MouseInit' is the only way to enforce the change. 
  1296.  
  1297.                   If the mouse is used in interrupt-driven mode, it  is a good practice to
  1298.             call 'MouseUnInit' before exiting the program. This will restore any interrupt
  1299.             vectors hooked by the program to their original values.
  1300.  
  1301.             void MouseUnInit(void);
  1302.  
  1303.             The mouse can be controlled with the following functions:
  1304.  
  1305.             void MouseSetSpeed(int speed);
  1306.                  void MouseSetAccel(int thresh,int accel);
  1307.                  void MouseSetLimits(int x1,int y1,int x2,int y2);
  1308.                  void MouseGetLimits(int *x1,int *y1,int *x2,int *y2);
  1309.                  void MouseWarp(int x,int y);
  1310.  
  1311.             The library calculates the mouse position only from the mouse mickey counters.
  1312.             (To avoid the limit and 'rounding to  the next multiple of eight' problem with
  1313.             the Microsoft mouse driver when it finds itself in a graphics  mode unknown to
  1314.             it.)  The  'speed' parameter  to  the 'MouseSetSpeed'  function is  used  as a
  1315.             divisor, i.e. coordinate changes  are obtained by dividing the  mickey counter
  1316.             changes by this value. In high resolution graphics modes the value of one just
  1317.             works  fine, in low resolution  modes (320x200 or similar)  it is best set the
  1318.             speed to  two or three.  (Of course,  it also depends  on the sensitivity  the
  1319.             mouse.)  The 'MouseSetAccel' function is used to control the ballistic effect:
  1320.             if a mouse coordinate changes between  two samplings by more than the 'thresh'
  1321.             parameter, the change is multiplied by the 'accel' parameter. NOTE: some mouse
  1322.             drivers  perform  similar calculations  before  reporting  the coordinates  in
  1323.             mickeys. In this case the acceleration  done by the library will be additional
  1324.             to  the one already  performed by  the mouse driver.  The limits  of the mouse
  1325.             movement  can  be set  (passed  limits will  be  clipped to  the  screen) with
  1326.             'MouseSetLimits'  (default is the whole screen)  and the current limits can be
  1327.             obtained with  'MouseGetLimits'.  'MouseWarp' sets  the  mouse cursor  to  the
  1328.             specified position.
  1329.  
  1330.                   As typical  mouse drivers do not know how  to draw mouse cursors in high
  1331.             resolution graphics modes, the mouse cursor is drawn by the library. The mouse
  1332.             cursor can be set with:
  1333.  
  1334.             void MouseSetCursor(GrCursor *cursor);
  1335.                  void MouseSetColors(int fg,int bg);
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.             LIBGRX graphics library user's manual                                       25
  1342.  
  1343.  
  1344.           'MouseSetColors' uses an  internal arrow pattern, the color 'fg'  will be used
  1345.             as  the interior of it and  'bg' will be the border.  The current mouse cursor
  1346.             can be obtained with:
  1347.  
  1348.             GrCursor *MouseGetCursor(void);
  1349.  
  1350.             The mouse cursor can be displayed/erased with:
  1351.  
  1352.             void MouseDisplayCursor(void);
  1353.                  void MouseEraseCursor(void);
  1354.  
  1355.             The  mouse cursor can be  left permanently displayed.  All graphics primitives
  1356.             except for the few non-clipping  functions check for conflicts with the  mouse
  1357.             cursor and erase it before the drawing if necessary. Of course, it may be more
  1358.             efficient  to erase  the cursor  manually before a  long drawing  sequence and
  1359.             redraw it after  completion. The library provides an alternative pair of calls
  1360.             for this purpose which  will erase the cursor  only if it interferes  with the
  1361.             drawing:
  1362.  
  1363.             int  MouseBlock(GrContext *c,int x1,int y1,int x2,int y2);
  1364.                  void MouseUnBlock(void);
  1365.  
  1366.             'MouseBlock' should be passed the context in which the drawing will take place
  1367.             (the  usual convention of  NULL meaning the current  context is supported) and
  1368.             the  limits  of  the  affected area.  It  will  erase the  cursor  only  if it
  1369.             interferes  with  the   drawing.  If   it  returns  a   non-zero  value   then
  1370.             'MouseUnBlock' has to be called at the end of the drawing, otherwise it should
  1371.             not be called.
  1372.  
  1373.                   The library supports (beside  the simple cursor drawing) three  types of
  1374.             "rubberband" attached  to the mouse cursor.  The 'MouseSetCursorMode' function
  1375.             is used to select the cursor drawing mode.
  1376.  
  1377.             void MouseSetCursorMode(int mode,...);
  1378.  
  1379.             The parameter 'mode' can have the following values:
  1380.  
  1381.             /*
  1382.                   * MOUSE CURSOR modes:
  1383.                   *  M_CUR_NORMAL -- just the cursor
  1384.                   *  M_CUR_RUBBER -- rectangular rubber band (XOR-d to the screen)
  1385.                   *  M_CUR_LINE   -- line attached to the cursor
  1386.                   *  M_CUR_BOX    -- rectangular box dragged by the cursor
  1387.                   */
  1388.                  #define M_CUR_NORMAL    0
  1389.                  #define M_CUR_RUBBER    1
  1390.                  #define M_CUR_LINE      2
  1391.                  #define M_CUR_BOX       3
  1392.  
  1393.             'MouseSetCursorMode'  takes  different  parameters  depending  on  the  cursor
  1394.             drawing mode selected. The accepted call formats are:
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.                  LIBGRX graphics library user's manual                                                       26
  1401.  
  1402.  
  1403.           MouseSetCursorMode(M_CUR_NORMAL);
  1404.                  MouseSetCursorMode(M_CUR_RUBBER,xanchor,yanchor,color);
  1405.                  MouseSetCursorMode(M_CUR_LINE,xanchor,yanchor,color);
  1406.                  MouseSetCursorMode(M_CUR_BOX,dx1,dy1,dx2,dy2,color);
  1407.  
  1408.             The anchor parameters for the rubberband  and rubberline modes specify a fixed
  1409.             screen location to which the other corner of the primitive is bound. The 'dx1'
  1410.             through 'dy2' parameters define the offsets  of the corners of the dragged box
  1411.             from the hotpoint of the mouse cursor. The color value passed is always XOR-ed
  1412.             to the  screen, i.e.  if an application  wants the  rubberband to appear  in a
  1413.             given  color on a given  background then it  has to pass the  XOR of these two
  1414.             colors to 'MouseSetCursorMode'.
  1415.  
  1416.             The   status  of   the   mouse   cursor   can   be   obtained   with   calling
  1417.             'MouseCursorIsDisplayed'. This function will return non-zero if  the cursor is
  1418.             displayed, zero if it is erased.
  1419.  
  1420.             int  MouseCursorIsDisplayed(void);
  1421.  
  1422.                   The  'MouseGetEvent'  function  is used  to  obtain  the  next mouse  or
  1423.             keyboard event. It takes a  flag with various bits encoding the type  of event
  1424.             needed.  It  returns  the event  in  a  'MouseEvent'  structure. The  relevant
  1425.             declarations from "mousex.h":
  1426.  
  1427.             void MouseGetEvent(int flags,MouseEvent *event);
  1428.  
  1429.                  typedef struct {
  1430.                      int  flags;                         /* flags (see above) */
  1431.                      int  x,y;                           /* coordinates */
  1432.                      int  buttons;                       /* button state */
  1433.                      int  key;                           /* key code from keyboard */
  1434.                      int  kbstat;                        /* keybd status (ALT, CTRL, etc..) */
  1435.                      long time;                          /* time stamp of the event */
  1436.                  } MouseEvent;
  1437.  
  1438.             The event  structure has been  extended with  a keyboard status  word (thus  a
  1439.             program  can check for combinations  like ALT-<left mousebutton  press>) and a
  1440.             time  stamp (in DOS clock  ticks since the start of  the program) which can be
  1441.             used to check for double clicks, etc... The following macros have been defined
  1442.             in "mousex.h" to  help in creating  the control  flag for 'MouseGetEvent'  and
  1443.             decoding the various bits in the event structure:
  1444.  
  1445.             /*
  1446.                   * MOUSE event flag bits
  1447.                   */
  1448.                  #define M_MOTION        0x001
  1449.                  #define M_LEFT_DOWN     0x002
  1450.                  #define M_LEFT_UP       0x004
  1451.                  #define M_RIGHT_DOWN    0x008
  1452.                  #define M_RIGHT_UP      0x010
  1453.                  #define M_MIDDLE_DOWN   0x020
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.                  LIBGRX graphics library user's manual                                                       27
  1460.  
  1461.  
  1462.           #define M_MIDDLE_UP     0x040
  1463.                  #define M_BUTTON_DOWN   (M_LEFT_DOWN | M_MIDDLE_DOWN | M_RIGHT_DOWN)
  1464.                  #define M_BUTTON_UP     (M_LEFT_UP   | M_MIDDLE_UP   | M_RIGHT_UP)
  1465.                  #define M_BUTTON_CHANGE (M_BUTTON_UP | M_BUTTON_DOWN )
  1466.  
  1467.                  /*
  1468.                   * MOUSE button status bits
  1469.                   */
  1470.                  #define M_LEFT          1
  1471.                  #define M_RIGHT         2
  1472.                  #define M_MIDDLE        4
  1473.  
  1474.                  /*
  1475.                   * Other bits and combinations
  1476.                   */
  1477.                  #define M_KEYPRESS      0x080           /* keypress */
  1478.                  #define M_POLL          0x100           /* do not wait for the event */
  1479.                  #define M_NOPAINT       0x200
  1480.                  #define M_EVENT         (M_MOTION | M_KEYPRESS | M_BUTTON_DOWN | M_BUTTON_UP)
  1481.  
  1482.                  /*
  1483.                   * KEYBOARD status word bits
  1484.                   */
  1485.                  #define KB_RIGHTSHIFT   0x01            /* right shift key depressed */
  1486.                  #define KB_LEFTSHIFT    0x02            /* left shift key depressed */
  1487.                  #define KB_CTRL         0x04            /* CTRL depressed */
  1488.                  #define KB_ALT          0x08            /* ALT depressed */
  1489.                  #define KB_SCROLLOCK    0x10            /* SCROLL LOCK active */
  1490.                  #define KB_NUMLOCK      0x20            /* NUM LOCK active */
  1491.                  #define KB_CAPSLOCK     0x40            /* CAPS LOCK active */
  1492.                  #define KB_INSERT       0x80            /* INSERT state active */
  1493.  
  1494.                  #define KB_SHIFT        (KB_LEFTSHIFT | KB_RIGHTSHIFT)
  1495.  
  1496.             'MouseGetEvent' will display the mouse cursor if it  was previously erased and
  1497.             the 'M_NOPAINT' bit is not set in the flag passed to it. In this case it  will
  1498.             also erase the cursor after an event has been obtained.
  1499.  
  1500.             NOTE: some  of the mouse  event constants  have different values  than in  the
  1501.             original  DJGPP graphics library. This  change was necessary  to better follow
  1502.             the mouse driver conventions for assigning bits with similar functions.
  1503.  
  1504.             The  generation of  mouse and keyboard  events can be  individually enabled or
  1505.             disabled   (by  passing  a  non-zero  or  zero,  respectively,  value  in  the
  1506.             corresponding 'enable_XX' parameter) by calling:
  1507.  
  1508.             void MouseEventEnable(int enable_kb,int enable_ms);